package com.theta.gateway.infra.common.exception.enums;

public enum ErrorEnum {
	SUCCESS(0,"操作成功"),
	/**
	 * 未知异常
	 */
	UNKNOWN_ERROR(-1, "未知异常，请联系系统管理员"),
	TIME_OUT(504, "处理请求超时"),
	NO_AUTHORITY(403,"您无权限访问此资源"),

	VALIDATE_CODE_EXPIRED(10002,"验证码已过期"),
	VALIDATE_CODE_ERROR(10003,"验证码不正确"),
	USER_IS_NULL(10004,"用户不存在"),
	DECRYPT_ERROR(10005,"解密失败"),
	MOBILE_PHONE_ERROR(10006,"手机号码不正确"),
	SEND_MESSAGE_ERROR(10007,"发送验证短信失败,请稍后重试"),
	VALIDATE_MESSAGE_ERROR(10008,"短信验证码校验失败,请重新获取"),
	REQUEST_PARAM_ERROR(10009,"缺少参数-%s"),
	PARAMS_VALID_ERROR(10010, "参数校验异常：%s"),
	NOT_LOGIN(10401, "用户未登陆或已失效"),
	NOT_AUTHORIZED(10403, "未授权的操作"),
	USER_PASSWORD_ERROR(10012,"用户名或密码错误"),

	ERROR_PARAM(10012, "参数不正确"),
	ERROR_RETURN(10013, "结果不正确"),
	
	ROUTE_PARAM_PARSE_ERROR(100001,"请求参数解析失败"),


	ROUTE_GATEWAY_SAVE_ERROR(200001,"增加网关路由信息失败：%s"),
	ROUTE_GATEWAY_UPDATE_ERROR(200002,"更新网关路由信息失败：%s"),
	ROUTE_GATEWAY_DELETE_ERROR(200003,"删除网关路由信息失败：%s"),
	ROUTE_GATEWAY_REFRESH_ERROR(200004,"刷新网关路由信息失败：%s"),
	ROUTE_GATEWAY_ROUTE_ID_NOTEXIST(200005,"网关路由ID不存在：%s"),

	ROUTE_CFG_PATH_INVALID(200101,"路由地址格式不正确：%s"),
	ROUTE_CFG_ID_NOT_EXIST(200102,"路由ID不存在"),
	ROUTE_CFG_SAVE2DB_ERROR(200103,"保存路由配置至数据库信息失败：%s"),
	ROUTE_CFG_SAVE2GATEWAY_ERROR(200104,"更新网关路由配置信息失败：%s"),

	SSO_FEIGN_AUTHENTICATION_ERROR(300001,"调用SSO认证接口失败")
	;

	//##########################################################

	private int code;
	private String message;
	ErrorEnum(int code, String message) {
		this.code = code;
		this.message = message;
	}

	public int getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}
	
	public static ErrorEnum getErrorEnum(int code) {
		for(ErrorEnum e:ErrorEnum.values()) {
			if(e.getCode()==code) {
				return e;
			}
		}
		return null;
	}

}
